/*    */ package client;
/*    */ 
/*    */ import com.alibaba.druid.pool.DruidPooledConnection;
/*    */ import java.io.Serializable;
/*    */ import java.sql.PreparedStatement;
/*    */ import java.sql.SQLException;
/*    */ import java.util.HashMap;
/*    */ import java.util.Map;
/*    */ import tools.Pair;
/*    */ import tools.data.output.MaplePacketLittleEndianWriter;
/*    */ 
/*    */ 
/*    */ public class MapleKeyLayout
/*    */   implements Serializable
/*    */ {
/*    */   private static final long serialVersionUID = 9179541993413738569L;
/*    */   private final Map<Integer, Pair<Byte, Integer>> keymap;
/*    */   private boolean changed = false;
/*    */   
/*    */   public MapleKeyLayout() {
/* 21 */     this.keymap = new HashMap<>();
/*    */   }
/*    */   
/*    */   public MapleKeyLayout(Map<Integer, Pair<Byte, Integer>> keys) {
/* 25 */     this.keymap = keys;
/*    */   }
/*    */   
/*    */   public Map<Integer, Pair<Byte, Integer>> Layout() {
/* 29 */     this.changed = true;
/* 30 */     return this.keymap;
/*    */   }
/*    */   
/*    */   public void unchanged() {
/* 34 */     this.changed = false;
/*    */   }
/*    */   
/*    */   public void writeData(MaplePacketLittleEndianWriter mplew, int lines) {
/* 38 */     mplew.write(this.keymap.isEmpty() ? 1 : 0);
/* 39 */     if (this.keymap.isEmpty()) {
/*    */       return;
/*    */     }
/*    */     
/* 43 */     for (int i = 0; i < lines; i++) {
/* 44 */       for (int x = 0; x < 89; x++) {
/* 45 */         Pair<Byte, Integer> binding = this.keymap.get(Integer.valueOf(x));
/* 46 */         if (binding != null) {
/* 47 */           mplew.write(((Byte)binding.getLeft()).byteValue());
/* 48 */           mplew.writeInt(((Integer)binding.getRight()).intValue());
/*    */         } else {
/* 50 */           mplew.write(0);
/* 51 */           mplew.writeInt(0);
/*    */         } 
/*    */       } 
/*    */     } 
/*    */   }
/*    */   
/*    */   public void saveKeys(DruidPooledConnection con, int charid) throws SQLException {
/* 58 */     if (!this.changed) {
/*    */       return;
/*    */     }
/* 61 */     PreparedStatement ps = con.prepareStatement("DELETE FROM keymap WHERE characterid = ?");
/* 62 */     ps.setInt(1, charid);
/* 63 */     ps.execute();
/* 64 */     ps.close();
/* 65 */     if (this.keymap.isEmpty()) {
/*    */       return;
/*    */     }
/* 68 */     ps = con.prepareStatement("INSERT INTO keymap VALUES (DEFAULT, ?, ?, ?, ?)");
/* 69 */     for (Map.Entry<Integer, Pair<Byte, Integer>> keybinding : this.keymap.entrySet()) {
/* 70 */       ps.setInt(1, charid);
/* 71 */       ps.setInt(2, ((Integer)keybinding.getKey()).intValue());
/* 72 */       ps.setByte(3, ((Byte)((Pair)keybinding.getValue()).getLeft()).byteValue());
/* 73 */       ps.setInt(4, ((Integer)((Pair)keybinding.getValue()).getRight()).intValue());
/* 74 */       ps.execute();
/*    */     } 
/* 76 */     ps.close();
/*    */   }
/*    */ }


/* Location:              C:\PGX\Server.jar!\client\MapleKeyLayout.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */